<html>
 <head>
  <title>Script to Show Database</title>
 </head>
 <body>

<?php

   /* Database information */
    include_once("../submit/pword.php");
	
	//Connect to the database
	$db = mysql_connect("$server", "$username", "$password") or die(mysql_error());
	mysql_select_db("cs1630History") or die(mysql_error());

getLocation("CONNECTICUT", "FAIRFIELD", "");

getLocation("CONNECTICUT", "FAIRFIELD", NULL);

getLocation("NEW YORK", "", "");


function getLocation($state, $county, $city)
{

    
    $city = strtoupper($city);
    $county = strtoupper($county);
    $state = strtoupper($state);
    
    
    echo "<hr />";
    $query = "SELECT * FROM location_with_gis WHERE name = '$city' OR name = '$county' OR name = '$state'";

    echo $query . "<br />";
    
    $result = mysql_query($query) or die(mysql_error());
    
    
    $num = mysql_num_rows($result);
    
    //echo $num;
    //echo "<br /><br />";
?>
   <table border = 1 cellpadding = 5>
   <caption>Location Return</caption>
   <tr align = center>

<?php   
    
    $data = mysql_fetch_array($result, MYSQL_ASSOC);
    
    $keys = array_keys($data);
        
    
    foreach ($keys as $next_key):
             echo "<th>$next_key</th>";
    endforeach;
    echo "</tr>"; 
    
    //var_dump($keys);
    
    for( $i = 0; $i < $num; $i++)
    {
        echo "<tr align = center>";
        foreach ($data as $col)
        {
                  echo "<td> $col </td>";
        }
        $data = mysql_fetch_array($result, MYSQL_ASSOC);
        //echo "<br />";
        echo "</tr>";
    } 
    
    echo "</table><br />";

      
}

 mysql_close($db); 
?>

 </body>
</html>
